package cn.edu.zzuli.search;

import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.document.Document;
import org.apache.lucene.search.MultiSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;

import cn.edu.zzuli.web.bean.Forum;

public class SearchResultBean {

	
	/**
	 * 返回索引结果集
	 * @Title: setCustomersB 
	 * @Description:
	 */
	public List<Forum> setCustomers(MultiSearcher searcher,TopDocs topDocs){
		List<Forum> list = new ArrayList<Forum>();
		try{
			ScoreDoc[] scoreDocs = topDocs.scoreDocs; 
			Document doc = null;
			Forum forum =  null;
			for(int i=0 ;i<topDocs.totalHits;i++){
				forum = new Forum();
				doc = searcher.doc(scoreDocs[i].doc);
				forum.setId(Integer.parseInt(doc.get("id")));
				forum.setTitle(doc.get("title"));
				forum.setContent(doc.get("content"));
				list.add(forum);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
	}
	
	

}
